Skip to content

Guard gearman_log_error() against NULL error strings#476

Merged
esabol merged 1 commit into
gearman:masterfrom
p-alik:fix-log-error-null-check
Jul 18, 2026
Merged

Guard gearman_log_error() against NULL error strings#476
esabol merged 1 commit into
gearman:masterfrom
p-alik:fix-log-error-null-check

Conversation

@p-alik

@p-alik p-alik commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • gearman_universal_st::error() returns nullptr when the error code is GEARMAN_SUCCESS, but gearman_log_error() (libgearman/log.cc) passed that value straight to the user-supplied log_fn callback without a NULL check.
  • Every other logging path in the file (gearman_log, _info, _debug) formats into a local buffer via vsnprintf and can therefore never hand log_fn a NULL pointer — gearman_log_error was the one path that could crash a log_fn implementation that assumes a valid string (e.g. strlen/fprintf("%s", line)).
  • None of the current callers (all in error.cc) trigger this today since they always set a real error code first, but it's a latent footgun for any future or embedder call path.

Test plan

  • Build passes (configure && make)
  • Existing libgearman test suite passes

gearman_universal_st::error() returns nullptr when the error code is
GEARMAN_SUCCESS, but gearman_log_error() passed that value straight
to the user-supplied log_fn callback with no NULL check. Every other
logging path in this file formats into a local buffer via vsnprintf
and can never hand log_fn a NULL pointer, so this was the one path
that could crash a log_fn implementation that assumes a valid string
(e.g. strlen/fprintf("%s", line)).

Signed-off-by: Alexei Pastuchov <info@maximka.de>

@esabol esabol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine. Thanks!

@esabol
esabol merged commit 908144b into gearman:master Jul 18, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants